package com.shanpin.shebao.web.module.game;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.shanpin.core.http.MJsonView;
import com.shanpin.shebao.web.module.game.vo.GameStatisVO;

@Controller
@RequestMapping("/game/statis")
public class GameStatisController {
	
	@Autowired
	private GameStatisService gameStatisService;
	
	@RequestMapping(path="/list", method=RequestMethod.GET)
	public ModelAndView list(String auth, String refresh) {
		List<GameStatisVO> statisList = Collections.emptyList();
		if("shanp_statis_123456".equals(auth)) {
			if("yyyyy".equals(refresh)) {
				gameStatisService.uodateStatisEventToDB();
			}
			statisList = gameStatisService.listStatisEvent();
			Collections.sort(statisList, new Comparator<GameStatisVO>() {
				@Override
				public int compare(GameStatisVO o1, GameStatisVO o2) {
					int c = o1.getEvent()-o2.getEvent();
					if(c == 0) {
						c = o1.getEventExt().compareTo(o2.getEventExt());
					}
					return c;
				}
			});
		}
		return MJsonView.ok(statisList);
	}
	
}
